<!--  -->
<template>
  <div class="lsh-box">
    <div class="lsh-left">
      <div
        :class="{
          'lsh-text-item': true,
          'lsh-text-active': item.id === activeTextId,
        }"
        v-for="item in leftTextList"
        :key="item.id"
        @click="activeTextId = item.id">
        {{ item.text }}
      </div>
    </div>
    <div class="lsh-right">
      <div class="lsh-right-top">
        <img
          class="lsh-img"
          :src="bigImgSrc" />
      </div>
      <div class="lsh-right-bottom">
        <div
          :class="{
            'lsh-img-box': true,
            'lsh-img-active': item.id === activeImgId,
          }"
          v-for="item in textList"
          :key="item.id"
          :src="item.src"
          @click="hanClickTextImg(item)">
          <img
            class="lsh-img"
            :src="item.src" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
const leftTextList = ref(
  new Array(100).fill(1).map((_, i) => ({
    id: i,
    text: `${i}`,
  }))
);
const padToDigits = (num: number, length: number): string => {
  return num.toString().padStart(length, "0");
};
function getRandomNumber(start:number,end:number) {
  return Math.floor(Math.random() * (end -1)) + start;
}
const getSrc = () =>{
  const num = getRandomNumber(2,69);
  const endPath = getRandomNumber(0,1) === 0 ?'A' :'B';
  return `https://test-xzt.chaoxing.com/proxy/guji/cache/${padToDigits(num, 4)}${endPath}.jpg`
}
const textList = ref(
  new Array(200).fill(1).map((_, i) => ({
    id: i,
    src: `https://test-xzt.chaoxing.com/proxy/guji/cache/785bf2b2_${padToDigits(i + 1, 5)}.jpg`,
  }))
);
const activeImgId = ref(0);
const activeTextId = ref(0);
const bigImgSrc = ref(getSrc());
const hanClickTextImg = (item: any) => {
  activeImgId.value = item.id;
  bigImgSrc.value = getSrc();
};
</script>
<style scoped lang="less">
.lsh-box {
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  gap: 20px;
  background: #f6f8fc;
  .lsh-left {
    width: 250px;
    flex-shrink: 0;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: auto;
    padding: 12px;
    .lsh-text-item {
      padding: 12px;
      background: #f7f8f9;
      border-radius: 4px;
      font-size: 14px;
      cursor: pointer;
      border: 1px solid transparent;

      &.lsh-text-active {
        border-color: #3a8bff;
      }
    }
  }
  .lsh-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
    .lsh-right-top {
      height: 300px;
      overflow: hidden;
      background: #fff;
    }
    .lsh-right-bottom {
      flex: 1;
      display: flex;
      flex-wrap: wrap;
      gap: 20px;
      overflow: auto;
      background: #fff;
      padding: 20px;
      .lsh-img-box {
        width: 112px;
        height: 112px;
        overflow: hidden;
        cursor: pointer;
        border-color: #3a8bff;
        border: 1px solid transparent;
        padding: 12px;
        background: #f7f8f9;
        border-radius: 4px;
        &.lsh-img-active {
          border-color: #3a8bff;
        }
      }
    }
    .lsh-img {
      width: 100%;
      height: 100%;
      object-fit: contain;
    }
  }
}
</style>
